# -*- coding: utf-8 -*-
"""URL definitions."""
from tipfy import HandlerPrefix, Rule, Submount

# XXX
# kwargs = {'defaults': {'area_name': 'www'}}

"""
Rule('/<any(newest, hot, votes, active):order_by>.atom', name='answers/atom-main', handler='TopicListFeedHandler'),
Rule('/unanswered/', name='answers/unanswered', handler='UnansweredHandler', defaults={'order_by': 'newest'}),
Rule('/unanswered/<any(hot, votes, active):order_by>', name='answers/unanswered', handler='UnansweredHandler'),
Rule('/unanswered/<any(newest, hot, votes, active):order_by>.atom', name='answers/atom-unanswered', handler='AtomUnansweredHandler'),
Rule('/question/<int:question_id>.atom', name='answers/atom-topic', handler=''),
Rule('/question/<int:question_id>-<slug>.atom', name='answers/atom-topic', handler='FeedByQuestionHandler'),
Rule('/tags/', name='answers/tags', handler='TagsHandler'),
Rule('/tags/<name>/', name='answers/tag', handler='TagHandler', defaults={'order_by': 'newest'}),
Rule('/tags/<name>/<any(hot, votes, active):order_by>', name='answers/tag', handler='TagHandler'),
Rule('/tags/<name>/<any(newest, hot, votes, active):order_by>.atom', name='answers/atom-tag', handler='FeedByTagHandler'),

Rule('/question/<int:question_id>/delete', name='answers/delete', handler='DeletePostHandler'),
Rule('/question/<int:question_id>/restore', name='answers/restore', handler='RestorePostHandler'),
Rule('/question/<int:question_id>/revisions', name='answers/revisions', handler='PostRevisionsHandler'),
"""

rules = [
    # Home page (points to the wiki start page)
    Rule('/', endpoint='home/index', handler='moe.wiki.handlers.ViewHandler'),
    # Answers.
    HandlerPrefix('moe.answers.handlers.', [
        Submount('/answers', [
            # Lists all topics ordered by: newest, active, hot and votes.
            Rule('/', name='answers/index', handler='QuestionListHandler', defaults={'order_by': 'newest'}),
            Rule('/<any(active, hot, votes):order_by>', name='answers/index', handler='QuestionListHandler'),
            Rule('/question/<int:question_id>-<slug>', name='answers/view', handler='QuestionViewHandler'),
            Rule('/question/<int:question_id>', name='answers/view', handler='QuestionViewHandler'),
            # Add or edit a question.
            Rule('/ask', name='answers/new', handler='QuestionEditHandler'),
            Rule('/question/<int:question_id>/edit', name='answers/edit', handler='QuestionEditHandler'),
        ]),
    ]),
    # Users
    HandlerPrefix('moe.users.handlers.', [
        Submount('/users', [
            Rule('/', name='users/index', handler='UserListHandler'),
            Rule('/signup', name='auth/signup', handler='SignupHandler'),
            Rule('/login', name='auth/login', handler='LoginHandler'),
            Rule('/logout', name='auth/logout', handler='LogoutHandler'),
            Rule('/new', name='users/new', handler='SignupHandler'),
            Rule('/forgot-password', name='users/forgot-password', handler='ForgotPasswordHandler'),
            Rule('/<username>', name='users/profile', handler='UserProfileHandler'),
            Rule('/<username>/edit', name='users/edit-profile', handler='EditProfileHandler'),
            #
            Rule('/set-favorite', name='users/set-favorite', handler='UserFavoriteHandler'),
        ]),
    ]),
    # Pastebin
    HandlerPrefix('moe.pastebin.handlers.', [
        Submount('/paste', [
            Rule('/', name='pastebin/index', handler='PasteEditHandler'),
            Rule('/+<language>', name='pastebin/index', handler='PasteEditHandler'),
            Rule('/view/<int:paste_id>', name='pastebin/view', handler='PasteViewHandler'),
            Rule('/view-raw/<int:paste_id>', name='pastebin/view-raw', handler='PasteViewRawHandler'),
        ]),
    ]),
    # Wiki
    HandlerPrefix('moe.wiki.handlers.', [
        Submount('/wiki', [
            # Initial page.
            Rule('/', name='wiki/index', handler='ViewHandler'),
            # A wiki page.
            Rule('/<path:page_path>', name='wiki/index', handler='ViewHandler'),
            # Internal pages.
            Submount('/pages', [
                # Base for the internal pages.
                Rule('/', name='wiki/pages', handler='OverviewHandler'),
                # Lists all pages.
                Rule('/list', name='wiki/list', handler='PageListHandler'),
                # Lists all child pages for a given page.
                Rule('/list/<path:page_path>', name='wiki/list', handler='PageListHandler'),
                # Lists all pages (Atom format).
                Rule('/list-atom', name='wiki/list-atom', handler='PageListFeedHandler'),
                # Lists all child pages for a given page (Atom format).
                Rule('/list-atom/<path:page_path>', name='wiki/list-atom', handler='PageListFeedHandler'),
                # Lists all changes.
                Rule('/changes', name='wiki/changes', handler='ChangesHandler'),
                # Lists all changes for a given page.
                Rule('/changes/<path:page_path>', name='wiki/changes', handler='PageChangesHandler'),
                # Lists all changes (Atom format).
                Rule('/changes-atom', name='wiki/changes-atom', handler='ChangesFeedHandler'),
                # Lists all changes for a given page (Atom format).
                Rule('/changes-atom/<path:page_path>', name='wiki/changes-atom', handler='PageChangesFeedHandler'),
                # Edition overview.
                Rule('/edit/', name='wiki/edit', handler='EditOverviewHandler'),
                # Edits a page.
                Rule('/edit/<path:page_path>', name='wiki/edit', handler='EditHandler'),
                # Diffs overview.
                Rule('/diff/', name='wiki/diff', handler='DiffOverviewHandler'),
                # Displays diffs for a page revision.
                Rule('/diff/<path:page_path>', name='wiki/diff', handler='DiffHandler'),
                # Displays all tags.
                Rule('/tags/', name='wiki/tags', handler='TagsHandler'),
                # Displays pages with a given tag.
                Rule('/tags/<tags>', name='wiki/tag', handler='TagHandler'),
                # Reparse all pages.
                # Rule('/reparse/', name='wiki/reparse', handler='ReparseHandler'),
            ]),
        ]),
    ]),
]
